<?php

/**
 * This is the model class for table "sys_ewallet_withdrawal".
 *
 * The followings are the available columns in table 'sys_ewallet_withdrawal':
 * @property string $ewallet_withdrawal_id
 * @property string $ewallet_withdrawal_network_id
 * @property string $ewallet_withdrawal_value
 * @property string $ewallet_withdrawal_datetime
 * @property string $ewallet_withdrawal_is_approve
 */
class sys_ewallet_withdrawal extends CActiveRecord
{
	public $member_mid;
	public $member_name;
	public $bank_no;
	public $bank_name;
	/**
	 * Returns the static model of the specified AR class.
	 * @return sys_ewallet_withdrawal the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'sys_ewallet_withdrawal';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ewallet_withdrawal_network_id', 'length', 'max'=>20),
			array('ewallet_withdrawal_value', 'length', 'max'=>10),
			array('member_name, bank_no, bank_name, member_mid','length','max'=>20),
			array('ewallet_withdrawal_is_approve', 'length', 'max'=>1),
			array('ewallet_withdrawal_datetime', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('member_name, bank_no, bank_name, member_mid, ewallet_withdrawal_id, ewallet_withdrawal_network_id, ewallet_withdrawal_value, ewallet_withdrawal_datetime, ewallet_withdrawal_is_approve', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		'ewallet_withdrawal_to_network'=>array(self::BELONGS_TO,'sys_network','ewallet_withdrawal_network_id'),

		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ewallet_withdrawal_id' => 'Ewallet Withdrawal',
			'ewallet_withdrawal_network_id' => 'Ewallet Withdrawal Network',
			'ewallet_withdrawal_value' => 'Ewallet Withdrawal Value',
			'ewallet_withdrawal_datetime' => 'Ewallet Withdrawal Datetime',
			'ewallet_withdrawal_is_approve' => 'Ewallet Withdrawal Is Approve',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ewallet_withdrawal_id',$this->ewallet_withdrawal_id,true);
		$criteria->compare('ewallet_withdrawal_network_id',$this->ewallet_withdrawal_network_id,true);
		$criteria->compare('ewallet_withdrawal_value',$this->ewallet_withdrawal_value,true);
		$criteria->compare('ewallet_withdrawal_datetime',$this->ewallet_withdrawal_datetime,true);
		$criteria->compare('ewallet_withdrawal_is_approve',$this->ewallet_withdrawal_is_approve,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	public function search_withdrawal_ewallet()
	{
		$criteria=new CDbCriteria;

		$criteria->addCondition('ewallet_withdrawal_is_approve="1"');
		
		if(isset($_GET['years']))
		{
			$criteria->addCondition('year(ewallet_withdrawal_datetime)="'.$_GET['years'].'"');
		}
		if(isset($_GET['month']))
                {
                        $criteria->addCondition('month(ewallet_withdrawal_datetime)="'.$_GET['month'].'"');
                }

		$criteria->with=array('ewallet_withdrawal_to_network',
				      'ewallet_withdrawal_to_network.rel_network_to_member',
				      'ewallet_withdrawal_to_network.rel_network_to_member.rel_member_to_ref_bank');
		$criteria->together=true;

		$data=new CActiveDataProvider($this,array(
					'criteria'=>$criteria,
                                        'pagination'=>array('pageSize'=>50),
				));

		$criteria->compare('ewallet_withdrawal_id',$this->ewallet_withdrawal_id,true);
                $criteria->compare('ewallet_withdrawal_network_id',$this->ewallet_withdrawal_network_id,true);
                $criteria->compare('ewallet_withdrawal_value',$this->ewallet_withdrawal_value,true);
                $criteria->compare('ewallet_withdrawal_datetime',$this->ewallet_withdrawal_datetime,true);
                $criteria->compare('ewallet_withdrawal_is_approve',$this->ewallet_withdrawal_is_approve,true);

		/*
			CUSTOM SEARCH
		*/
		$criteria->compare('ewallet_withdrawal_to_network.network_mid',$this->member_mid, true);
		$criteria->compare('rel_network_to_member.member_name',$this->member_name, true);
 		$criteria->compare('rel_member_to_ref_bank.bank_name',$this->bank_name, true);
		$criteria->compare('rel_network_to_member.member_bank_account_no',$this->bank_no, true);
		
		$_SESSION['data_export']=$data;
		return $data;
	}
}
